package com.taptech.doufu.weex.module;

import android.app.Activity;
import android.content.Intent;
import android.widget.Toast;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.taobao.weex.bridge.JSCallback;
import com.taobao.weex.common.WXModule;
import com.taobao.weex.common.WXModuleAnno;
import com.taptech.doufu.weex.TFGiftAnimationUtil;
import com.taptech.doufu.ui.activity.NoMoneyTipActivity;
import com.taptech.doufu.util.UIUtil;

/**
 * Created by qlx on 2016/12/10.
 */

public class TFHudModule extends WXModule {
    @WXModuleAnno(moduleMethod = true,runOnUIThread = true)
    public void showMessage(String text){
        dismiss();
        Toast.makeText(mWXSDKInstance.getContext(), text, Toast.LENGTH_SHORT).show();
    }

    @WXModuleAnno(moduleMethod = true,runOnUIThread = true)
    public void showError(String text){
        dismiss();
        Toast.makeText(mWXSDKInstance.getContext(), text, Toast.LENGTH_SHORT).show();
    }

    @WXModuleAnno(moduleMethod = true,runOnUIThread = true)
    public void showSuccess(String text){
        dismiss();
        Toast.makeText(mWXSDKInstance.getContext(), text, Toast.LENGTH_SHORT).show();
    }

    @WXModuleAnno(moduleMethod = true,runOnUIThread = true)
    public void showLoading(String text){
        UIUtil.showProgressDialog((Activity) mWXSDKInstance.getContext());
    }

    @WXModuleAnno(moduleMethod = true,runOnUIThread = true)
    public void dismiss(){
        UIUtil.dismissDialog();
    }

    @WXModuleAnno(moduleMethod = true,runOnUIThread = true)
    public void  alert(String jsonParam , JSCallback callback){

    }

    @WXModuleAnno(moduleMethod = true,runOnUIThread = true)
    public void showGiftLoading(String imageUrl){
        TFGiftAnimationUtil.loading(mWXSDKInstance.getContext(), imageUrl);
    }

    @WXModuleAnno(moduleMethod = true,runOnUIThread = true)
    public void dismissGift(String jsonParam){

        JSONObject param = JSON.parseObject(jsonParam);
        String msg = "";

        boolean animated = false;
        if (param.containsKey("animated")){
            animated = param.getBoolean("animated");
        }
        if (param.containsKey("text")){
            msg = param.getString("text");
            animated = true;
        }

        TFGiftAnimationUtil.close(msg,animated);

    }

    @WXModuleAnno(moduleMethod = true,runOnUIThread = true)
    public void showGiftMessageForRecharge(String text) {
        Intent intent = new Intent();
        intent.setClass(mWXSDKInstance.getContext(), NoMoneyTipActivity.class);
        intent.putExtra(NoMoneyTipActivity.INTENT_KEY_TIP, text);
        mWXSDKInstance.getContext().startActivity(intent);
    }

    @WXModuleAnno(moduleMethod = true,runOnUIThread = true)
    public void showGiftMessage(String text){
        Toast.makeText(mWXSDKInstance.getContext(), text, Toast.LENGTH_SHORT).show();
    }











}
